package net.office.service.impl;

import net.office.bean.MemorandumExample;
import net.office.bean.StaffInfo;
import net.office.bean.StaffInfoExample;
import net.office.mapper.StaffInfoMapper;
import net.office.service.StaffInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class StaffInfoServiceImpl implements StaffInfoService {

    @Autowired
    private StaffInfoMapper staffInfoMapper;

    @Override
    public List<StaffInfo> findAll() {
        StaffInfoExample example = new StaffInfoExample();
        return staffInfoMapper.selectByExample(example);
    }

    @Override
    public List<StaffInfo> findByStaffInfo(StaffInfo staffInfo) {

        StaffInfoExample example = new StaffInfoExample();
        StaffInfoExample.Criteria criteria = example.createCriteria();

        if(staffInfo.getStaffNo()!=null && staffInfo.getStaffNo().trim().length()!=0){
            criteria.andStaffNoLike("%" + staffInfo.getStaffNo() + "%");
        }
        if(staffInfo.getStaffDepartment()!=null && staffInfo.getStaffDepartment().trim().length()!=0){
            criteria.andStaffDepartmentLike("%" + staffInfo.getStaffDepartment() + "%");
        }
        if(staffInfo.getStaffPost()!=null && staffInfo.getStaffPost().trim().length()!=0){
            criteria.andStaffPostLike("%" + staffInfo.getStaffPost() + "%");
        }
        if(staffInfo.getStaffName()!=null && staffInfo.getStaffName().trim().length()!=0){
            criteria.andStaffNameLike("%" + staffInfo.getStaffName() + "%");
        }
        if(staffInfo.getStaffSex()!=null){
            criteria.andStaffSexEqualTo(staffInfo.getStaffSex());
        }
        if(staffInfo.getStaffBirthday()!=null){
            criteria.andStaffBirthdayEqualTo(staffInfo.getStaffBirthday());
        }
        if(staffInfo.getStaffIdCard()!=null && staffInfo.getStaffIdCard().trim().length()!=0){
            criteria.andStaffIdCardLike("%" + staffInfo.getStaffIdCard() + "%");
        }
        if(staffInfo.getStaffEntryDate()!=null){
            criteria.andStaffEntryDateEqualTo(staffInfo.getStaffEntryDate());
        }
        if(staffInfo.getStaffIsWork()!=null){
            criteria.andStaffIsWorkEqualTo(staffInfo.getStaffIsWork());
        }
        if(staffInfo.getStaffQuitDate()!=null){
            criteria.andStaffQuitDateEqualTo(staffInfo.getStaffQuitDate());
        }
        if(staffInfo.getStaffPassword()!=null && staffInfo.getStaffPassword().trim().length()!=0){
            criteria.andStaffPasswordLike("%" + staffInfo.getStaffPassword() + "%");
        }
        if(staffInfo.getRoleId()!=null){
            criteria.andRoleIdEqualTo(staffInfo.getRoleId());
        }
        if(staffInfo.getStaffDirectSuperId()!=null){
            criteria.andStaffDirectSuperIdEqualTo(staffInfo.getStaffDirectSuperId());
        }
        if(staffInfo.getStaffDirectSuperNo()!=null && staffInfo.getStaffDirectSuperNo().trim().length()!=0){
            criteria.andStaffDirectSuperNoLike("%" + staffInfo.getStaffDirectSuperNo() + "%");
        }
        if(staffInfo.getStaffDiractSuperName()!=null && staffInfo.getStaffDiractSuperName().trim().length()!=0){
            criteria.andStaffDiractSuperNameLike("%" + staffInfo.getStaffDiractSuperName() + "%");
        }
        if(staffInfo.getStaffCreateId()!=null){
            criteria.andStaffCreateIdEqualTo(staffInfo.getStaffCreateId());
        }
        if(staffInfo.getStaffCreateTime()!=null){
            criteria.andStaffCreateTimeEqualTo(staffInfo.getStaffCreateTime());
        }
        example.or(criteria);

        return staffInfoMapper.selectByExample(example);
    }

    @Override
    public StaffInfo findByPrimaryKey(Integer staffId) {

        return staffInfoMapper.selectByPrimaryKey(staffId);
    }

    @Override
    public int deleteByPrimaryKey(Integer staffInfoId) {
        return staffInfoMapper.deleteByPrimaryKey(staffInfoId);
    }

    @Override
    public int insert(StaffInfo staffInfo) {
        return staffInfoMapper.insertSelective(staffInfo);
    }

    @Override
    public int updateByPrimaryKey(StaffInfo staffInfo) {
        return staffInfoMapper.updateByPrimaryKey(staffInfo);
    }
}
